package impl;

import entity.Book;
import interfaces.Manager;

/**
 * 管理员实现类
 * @author yy
 *
 */
public class ManagerImpl implements Manager {
	/**
	 * 图书入库
	 * @param book
	 * @param inNum
	 * @return
	 */
	public boolean bookIn(Book book, int inNum){
		if(book != null){
			book.setStoreNum(book.getStoreNum() + inNum);
			return true;
		}
		return false;
	}
	/**
	 * 图书出库
	 * @param book
	 * @param outNum
	 * @return
	 */
	public boolean bookOut(Book book, int outNum){
		if(book != null){
			book.setStoreNum(book.getStoreNum() - outNum);
			return true;
		}
		return false;
	}

	@Override
	public void showBook(Book[] books) {
		System.out.println("ID\t书名\t库存\t价格");
		for (Book book : books) {
			if(book == null){
				continue;
			}
		System.out.println(book.getId() + "\t" + book.getName() +
					"\t" + book.getStoreNum() + "\t" + book.getPrice());
		}
	}
	
	public boolean addBook(Book[] books, Book book){
//		for (Book book2 : books) {
//			if(book2 == null){
//				book2 = new Book(book.getId(),book.getName(),
//						book.getStoreNum(),book.getPrice());
//				//book2 = book;
//				return true;
//			}
//		}
		for (int i = 0; i < books.length; i++) {
			if(books[i] ==null){
				books[i] = book;
				return true;
			}
		}
		return false;
		
	}
}
